package com.meixun.xuanke.user.activemq;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.meixun.xuanke.user.model.LoginLog;
import com.meixun.xuanke.user.service.LoginLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 消息接受处理
 */
@Component
public class MessageAcceptance {
    Logger logger = LoggerFactory.getLogger(MessageAcceptance.class);
    @Resource
    LoginLogService loginLogService;
    /**
     * 使用JmsListener配置消费者监听的队列
     *
     * @param text   接收到的消息
     */
    @JmsListener(destination = "mq.text")
    public void receiveTest(String text) {
        logger.info("第一个接受者:" + text);
    }

    /**
     * 登陆日志
     * @param json
     */
    @JmsListener(destination = "mq.userLoginLog")
    public void receiveLoginLog1(String json) {
        logger.info(json);
        LoginLog loginLog=JSON.parseObject(json, new TypeReference<LoginLog>() {});
        loginLogService.addLoginLog(loginLog);
    }

}
